package com.apesource.project02.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @version 1.0
 * @auther:暮雪
 * @date:2025/10/9
 */
@Configuration
@EnableSwagger2 //开启swagger自动配置
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("group1");
    }

    @Bean
    public Docket api2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("group2");
    }


    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_12)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.apesource.project02.controller")) //配置要扫描的包
                .paths(PathSelectors.ant("/user/**"))   //通过path进行过滤
                .build()
                .groupName("swagger");  //自定义组名;
    }

    //配置文档信息
    private ApiInfo apiInfo() {
        Contact contact = new Contact("暮雪","http://www.apesource.com/","apesource@apesource.com");
        return new ApiInfo(
                "西安度小满马拉松",//标题
                "基于springBoot的后端接口实现",  //项目描述
                "v2.0",  //版本
                "http://apesource.com", //组织链接
                contact,  //联系人相关信息
                "Apach 2.0 许可",  //许可
                "许可链接", //许可链接
                new ArrayList<>()  //扩展
                );
    }
}
